package com.li.toolkit.domain;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 6/26/2020 10:12 AM
 */
@SuppressWarnings("all")
public class ResponseInfo<T> {

    /**
     * 状态码
     */
    private Integer code;
    /**
     * 信息
     */
    private String message;
    /**
     * 返回结果
     */
    private T data;

    public ResponseInfo() {
    }

    public ResponseInfo(Integer responseCode) {
        code = responseCode;
    }

    public ResponseInfo(Integer responseCode, String responseMessage) {
        code = responseCode;
        message = responseMessage;
    }

    public ResponseInfo(Integer responseCode, T responseData) {
        code = responseCode;
        data = responseData;
    }

    public ResponseInfo(Integer responseCode, String responseMessage, T responseData) {
        code = responseCode;
        message = responseMessage;
        data = responseData;
    }

    /**
     * 失败
     *
     * @param code    状态码
     * @param message 信息
     * @param <T>     类型
     * @return T
     */
    public static <T> ResponseInfo<T> error(Integer code, String message) {
        return new ResponseInfo<>(code, message);
    }

    /**
     * 成功
     *
     * @param code    状态码
     * @param message 信息
     * @return T
     */
    public static <T> ResponseInfo<T> success(Integer code, String message) {
        return new ResponseInfo<>(code, message);
    }

    /**
     * 成功
     *
     * @return T
     */
    public static <T> ResponseInfo<T> success() {
        return new ResponseInfo<T>(ResultEnum.SUCCESS.getCode());
    }

    /**
     * 成功
     *
     * @param code   状态码
     * @param object object
     * @return T
     */
    public static <T> ResponseInfo<T> success(Integer code, T object) {
        return new ResponseInfo<>(code, object);
    }


    /**
     * 成功标志
     *
     * @param code    状态码
     * @param message 信息
     * @param object  内容
     * @return T
     */
    public static <T> ResponseInfo<T> success(Integer code, String message, T object) {
        return new ResponseInfo<>(code, message, object);
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return String.format("ResponseInfo{code=%d, message='%s', data=%s}", code, message, data);
    }
}
